package com.qingke.dao;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;

import org.apache.ibatis.session.SqlSession;

public class LoadService {

	static WordDao dao = new WordDao();

	public static void main(String[] args) {
		InputStream is = LoadService.class.getClassLoader().getResourceAsStream("danci2.txt");

		BufferedReader reader;
		try {
			reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));

			String line = reader.readLine();
			SqlSession session = SessionManager.getInstance().getSession();
			while (line != null) {
				int index = line.indexOf(" ");
				String en = line.substring(0, index).trim();
				String cn = line.substring(index, line.length() - 1).trim();
				System.out.println(en + cn);
				dao.insertWord(session, en, cn);
				line = reader.readLine();
			}
			session.commit();
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
}
